using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.Common;

/// <summary>
/// Summary description for GenericDataAccess
/// </summary>
public class GenericDataAccess
{
	static GenericDataAccess()
	{
	}

    public static DbCommand CreateCommand()
    {
        String providerName = KFCConfiguration.DbProviderName;
        String connectionString = KFCConfiguration.DbConnectionString;
        DbProviderFactory factory = DbProviderFactories.GetFactory(providerName);
        DbConnection connection = factory.CreateConnection();
        connection.ConnectionString = connectionString;
        DbCommand command = connection.CreateCommand();
        command.CommandType = CommandType.StoredProcedure;
        return command;
    }

    public static DataTable ExecuteSelectCommand(DbCommand command)
    {
        DataTable table = null;
        try
        {
            command.Connection.Open();
            DbDataReader reader = command.ExecuteReader();
            table = new DataTable();
            table.Load(reader);
            reader.Close();
        }
        catch
        {
            return table;
        }
        finally
        {
            command.Connection.Close(); 
        }
        return table;
    }
    public static void  ExecuteNoneQuery(DbCommand command)
    {
        try
        {
            command.Connection.Open();
            command.ExecuteNonQuery();
            command.Connection.Close();
        }
      
        catch (Exception ex) 
        { 
            Utilities.LogError(ex); 
            throw ex; 
            // xu ly cac exceptions sau 
        } 
    }

    
}
